package com.xgimi.open.skill.datamanager.domain.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.collect.Lists;
import com.xgimi.open.skill.datamanager.domain.entity.IntentSlotDO;
import com.xgimi.open.skill.datamanager.domain.mapper.IntentSlotMapper;
import com.xgimi.open.skill.datamanager.domain.service.IntentSlotService;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.List;
import java.util.Objects;

/**
 * @author coderzpw.zhang
 * @description 针对表【intent__slot(意图-槽位中间表)】的数据库操作Service实现
 * @createDate 2023-04-11 16:43:38
 */
@Service
public class IntentSlotServiceImpl extends ServiceImpl<IntentSlotMapper, IntentSlotDO>
        implements IntentSlotService {

    /**
     * 删除某个意图的所有记录信息
     *
     * @param intentId
     * @return
     */
    @Override
    public Boolean deleteByIntentId(Long intentId) {
        if (Objects.isNull(intentId)) {
            return Boolean.FALSE;
        }
        LambdaQueryWrapper<IntentSlotDO> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(IntentSlotDO::getIntentId, intentId);
        return this.remove(queryWrapper);
    }

    /**
     * 删除某个槽位的所有记录信息
     *
     * @param slotId
     * @return
     */
    @Override
    public Boolean deleteByslotId(Long slotId) {
        if (Objects.isNull(slotId)) {
            return Boolean.FALSE;
        }
        LambdaQueryWrapper<IntentSlotDO> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(IntentSlotDO::getSlotId, slotId);
        return this.remove(queryWrapper);
    }

    /**
     * 查询关联某个槽位的所有记录
     *
     * @param slotId
     * @return
     */
    @Override
    public List<IntentSlotDO> getBySlotId(Long slotId) {
        if (Objects.isNull(slotId)) {
            return Lists.newArrayList();
        }
        LambdaQueryWrapper<IntentSlotDO> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(IntentSlotDO::getSlotId, slotId);
        return this.list(queryWrapper);
    }

    /**
     * 查询关联某些槽位的所有记录
     *
     * @param slotIds
     * @return
     */
    @Override
    public List<IntentSlotDO> listBySlotIds(List<Long> slotIds) {
        if (CollectionUtils.isEmpty(slotIds)) {
            return Lists.newArrayList();
        }
        LambdaQueryWrapper<IntentSlotDO> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.in(IntentSlotDO::getSlotId, slotIds);
        return this.list(queryWrapper);
    }

    @Override
    public boolean physicalDeleteByIntentIds(List<Long> intentIds) {
        if (CollectionUtils.isEmpty(intentIds)) {
            return Boolean.FALSE;
        }
        return this.baseMapper.physicalDeleteByIntentIds(intentIds);
    }

    @Override
    public boolean physicalDeleteBySlotIds(List<Long> slotIds) {
        if (CollectionUtils.isEmpty(slotIds)) {
            return Boolean.FALSE;
        }
        return this.baseMapper.physicalDeleteBySlotIds(slotIds);
    }

    @Override
    public List<IntentSlotDO> listByIntentIds(List<Long> intentIds) {
        if (CollectionUtils.isEmpty(intentIds)) {
            return Lists.newArrayList();
        }
        LambdaQueryWrapper<IntentSlotDO> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.in(IntentSlotDO::getIntentId, intentIds);
        return this.list(queryWrapper);
    }

    /**
     * 根据 intentId、slotId查询
     * @param intentId
     * @param slotId
     * @return
     */
    @Override
    public IntentSlotDO queryByIntentIdAndSlotId(Long intentId, Long slotId) {
        if (Objects.isNull(intentId) || Objects.isNull(slotId)) {
            return null;
        }
        LambdaQueryWrapper<IntentSlotDO> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(IntentSlotDO::getIntentId, intentId);
        queryWrapper.eq(IntentSlotDO::getSlotId, slotId);
        return this.getOne(queryWrapper);
    }

    @Override
    public List<IntentSlotDO> listByIntentId(Long intentId) {
        if (Objects.isNull(intentId)) {
            return Lists.newArrayList();
        }
        LambdaQueryWrapper<IntentSlotDO> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(IntentSlotDO::getIntentId, intentId);
        return this.list(queryWrapper);
    }
}




